package cn.niu.itest;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.Arrays;
import java.util.List;

import cn.niu.itest.utils.GeneralAdapter;
import cn.niu.itest.utils.ViewHolder;

public class MainActivity extends AppCompatActivity {

    ListView listExampleView;

    GeneralAdapter<String> mAdapter;

    List<String> list = Arrays.asList(new String[]{"录音测试"});

    Class[] activities = {ConvertActivity.class};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listExampleView = (ListView) findViewById(R.id.list_example);
        initListView();
    }

    public void initListView() {
        mAdapter = new GeneralAdapter<String>(this, list, R.layout.list_item) {
            @Override
            public void initItemView(ViewHolder viewHolder, String info, int position) {
                viewHolder.setText(R.id.item_name, info);
            }
        };

        listExampleView.setAdapter(mAdapter);

        listExampleView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(MainActivity.this, activities[position]);
                startActivity(intent);
            }
        });
    }
}
